package config

import (
	"github.com/ethereum/go-ethereum/ethclient"
	"log"
	"time"
	"token-for-token/global"
)

func SetupEthClient() {
	var err error
	global.EthRpcClient, err = NewEthRpcClient()
	if err != nil {
		log.Println("NewEthRpcClient error : ", err)
		time.Sleep(time.Second * 1)
		SetupEthClient()
	}
}

func NewEthRpcClient() (*ethclient.Client, error) {
	client, err := ethclient.Dial(global.BlockChainConfig.RpcUrl)
	if err != nil {
		return nil, err
	}
	return client, nil
}
